<?php
/*
	
*/
defined('BY_JYA') or exit('Access Denied');
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
if($_RQ['op']=='main'){
	$basic=$this->plugin_setting('basic');
	$groupid=$_RQ['groupid'];
	set_html('title',$basic['title']?'报价列表-'.$basic['title']:'报价列表');
	$return['sharedata']=array(
		'title'=>$basic['share_title'],
		'desc'=>$basic['share_desc'],
		'link'=>custom_url('jy_shopbaojia/list//fromuser='.$_SESSION['uid'],true),
		'imgUrl'=>ATTACHMENT_URL.$basic['share_image'],
	);
	$return['params']=array('keyword'=>'');
	if($_RQ['keyword']){
		$return['params']['keyword']=$_RQ['keyword'];
	}
	if($_RQ['groupid']){
		$return['params']['groupid']=$groupid;
	}else{
		$return['params']['groupid']=0;
	}
	$return['groups']=pdo_getall('jy_shopbaojia_group',array('uniacid'=>$_SESSION['uniacid'],'status'=>'1','pid'=>0),'','','paixu desc');
	foreach($return['groups'] as &$item){
		$item['childs']=pdo_getall('jy_shopbaojia_group',array('uniacid'=>$_SESSION['uniacid'],'status'=>1,'pid'=>$item['id']),array(),'','paixu desc');
	}
	$return['childs']=$return['groups'][0]['childs'];
	$return['nowkey']=0;
	$return['nowchilds']=$return['groups'][0]['childs'];
	$return['nowchildid']=$return['groups'][0]['childs'][0]['id'];
	$return['list']=array();
	$return['placement_id']=$basic['ad_id1'];
	exi($return);
}
if($_RQ['op']=='pay'){
	$post=get_postdata();
	$listid=$post['listid'];
	if(!$listid){
		exi('请选择商品。','error');	
	}
	$id=$this->model('model')->add_log($listid,0,3,true);
	$params=array(
		'id'=>$id,
		'title'=>'看报价',
		'fee'=>$this->setting['kan_price'],
		//'pay_type'=>'wechat',//可选，此项作用为指定支付方式
		//'no_type'=>array('hdfk'),//可选，此项作用为指定不允许使用哪种支付方式
		'back_url'=>'jy_shopbaojia/list/payresult/',//必填，指定异步支付结果通知地址，采用系统标准URL书写格式
		'success_url'=>'jy_shopbaojia/list/',
		'error_url'=>'jy_shopbaojia/list/',
	);
	$payid=cfc('pay')->create_pay_order($params);
	$this->pdo_update('adlog',array('pay_id'=>$payid),array('id'=>$id));
	$res=array(
		'pay_id'=>$payid,
		'order_id'=>$id,
	);
	exi($res);
}
if($_RQ['op']=='payresult'){
	$payresult=$_SESSION['pay_result'];
	if($payresult['status']!=1 && $payresult['pay_type'] !='hdfk'){
		exi('支付失败。','error','jy_shopbaojia/list/');
	}
	$order=pdo_get('jy_shopbaojia_adlog',array('id'=>$payresult['id']));
	if($order['ispay'] ==1){
		exi('该订单已经支付！','error','jy_shopbaojia/list/');
	}
	if($order['fee']!=$payresult['fee']){
		exi('支付失败！订单金额不匹配！'.$order['fee'].'|'.$payresult['fee'],'error','jy_shopbaojia/list/');
	}
	$params=array(
		'paytype'=>$payresult['pay_type'],
		'transid'=>$payresult['transaction_id'],
	);
	$this->model('model')->order_pay($order['id'],$params);
	exi('提交成功!');
}
